package com.cct.digitalarchapi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.cct.digitalarchapi.common.CommonUtil;
import com.cct.digitalarchapi.common.Response;
import com.cct.digitalarchapi.pojo.ArchCategory;
import com.cct.digitalarchapi.service.ArchCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MultivaluedMap;


/**
 * @FileName ArchCategoryController
 * @Description 档案控制器
 * @Author Created by chenmingzhe
 * @Date 2023/11/19
 **/
@Slf4j
@RestController
@RequestMapping(value = "/archCategory")
public class ArchCategoryController {
    @Autowired
    private ArchCategoryService archCategoryService;
    @Autowired
    private CommonUtil commonUtil;
    /**
     *分页获取所有的档案分类
     */
    @RequestMapping(value = "/getAllCategory",method = RequestMethod.POST)
    public Response getAllCategory(@RequestBody JSONObject obj){
        int pageNum=obj.getInteger("pageNum");
        int pageSize=obj.getInteger("pageSize");
        //送空或不送代表所有，其他送对应状态 默认0 =首页可见分类，1=不可见，5=禁用
        String archCateType=obj.getString("archCateType");
        return  archCategoryService.getAllCategory(pageNum,pageSize,archCateType);
    }
    /**
     * 新增档案分类
     */
    @RequestMapping(value = "/addCategory",method = RequestMethod.POST)
    public Response addCategory(@RequestBody ArchCategory archCategory){
        commonUtil.recordOperateLog("新增档案分类名称为"+archCategory.getArchCateName()+"的档案分类");
        return  archCategoryService.addCategory(archCategory);
    }
    /**
     *根据id删除一个档案分类
     */
    @RequestMapping(value = "/deleteCategory",method = RequestMethod.POST)
    public Response deleteCategory(@RequestBody JSONObject obj){
        int archCateId = obj.getInteger("archCateId");
        commonUtil.recordOperateLog("删除了档案分类Id为"+archCateId+"的档案分类");
        return  archCategoryService.deleteCategory(archCateId);
    }
    /**
    *更新一个档案分类， archCateType，archRequireOther，notes
    */
    @RequestMapping(value = "/updateCategory",method = RequestMethod.POST)
    public Response updateCategory(@RequestBody ArchCategory archCategory){
        commonUtil.recordOperateLog("更新档案分类Id为"+archCategory.getArchCateId()+"的档案分类");
        return  archCategoryService.updateCategory(archCategory);
    }
}
